﻿<UserControl x:Class="PDOGenerator.Views.ColumnView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mapTypes="clr-namespace:PDOGenerator.MapTypes"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:util="clr-namespace:PDOGenerator.Util"

    MinHeight="300" MinWidth="300">
    <Grid>
        <Grid.Resources>
            
            <util:VisiblityValueConverter x:Key="visibilityConverter" />

            <Style TargetType="TextBox" >
                <Setter Property="Margin" Value="2,2,2,2" />
            </Style>
            <Style TargetType="CheckBox" >
                <Setter Property="Margin" Value="2,2,2,2" />
            </Style>
            <Style TargetType="RadioButton" >
                <Setter Property="Margin" Value="2,4,2,2" />
            </Style>
            <Style TargetType="TextBlock" >
                <Setter Property="Margin" Value="2,2,2,2" />
            </Style>

            <Style x:Key="VerticalRadioButtonListStyle" TargetType="ListBox">
                <Style.Resources>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Grid Margin="2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <RadioButton IsChecked="{Binding IsSelected,  
                                                                RelativeSource={RelativeSource TemplatedParent},  
                                                                Mode=TwoWay}" />
                                        <ContentPresenter Grid.Column="1" Margin="2,0,0,0" />
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Style.Resources>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Vertical"  />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Background" Value="Transparent" />
            </Style>

            <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="enumForeignKeyTypes"            >
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="mapTypes:ForeignKeyTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>

        </Grid.Resources>

        <StackPanel Orientation="Vertical">
            
            <StackPanel Orientation="Horizontal">
                <TextBlock FontWeight="Bold">Column</TextBlock>
                <TextBlock Text="{Binding ColumnName}" />
            </StackPanel>

            <StackPanel Orientation="Vertical" >

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Column Name:</TextBlock>
                    <TextBox Grid.Column="1" Text="{Binding Path=ColumnName}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Property Name:</TextBlock>
                    <TextBox Grid.Column="1" Text="{Binding Path=PropertyName}" />
                </Grid>
                
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Object Property Name:</TextBlock>
                    <TextBox Grid.Column="1" Text="{Binding Path=ObjectPropertyName}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Ignore:</TextBlock>
                    <CheckBox Grid.Column="1"  IsChecked="{Binding Path=Ignore}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Primary Key:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=IsPK}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Nullable:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=Nullable}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Identity:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=Identity}" />
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Foreign Key:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=IsFK}" />
                </Grid>
                
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Foreign Table:</TextBlock>
                    <TextBlock Grid.Column="1" Text="{Binding Path=CollectionTableMoniker}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsData, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Data Type:</TextBlock>
                    <TextBlock Grid.Column="1" Text="{Binding Path=DataType}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsData, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Database Type:</TextBlock>
                    <TextBlock Grid.Column="1" Text="{Binding Path=DBType}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsCollection, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Collection:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="False" IsChecked="{Binding Path=IsCollection}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsCollection, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Referenced List Name:</TextBlock>
                    <TextBox Grid.Column="1" Text="{Binding Path=ReferencedListName}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsCollection, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Singular Relationship:</TextBlock>
                    <CheckBox Grid.Column="1" IsEnabled="True" IsChecked="{Binding Path=IsSingularRelationship}" />
                </Grid>
                <Grid Visibility="{Binding Path=IsFK, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Foreign Type:</TextBlock>
                    <TextBlock Grid.Column="1" Text="{Binding Path=ForeignType}" />
                </Grid>

                <Grid Visibility="{Binding Path=IsFK, Converter={StaticResource visibilityConverter}, ConverterParameter=Collapsed}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock >Foreign Key Generation:</TextBlock>

                    <ListBox Grid.Column="1" Style="{StaticResource VerticalRadioButtonListStyle}"  
                        ItemsSource="{Binding Source={StaticResource enumForeignKeyTypes}}" 
                             SelectedValue="{Binding Path=ForeignKeyType}" IsSynchronizedWithCurrentItem="True"/>
                </Grid>
            </StackPanel>
        </StackPanel>



    </Grid>
</UserControl>
